﻿using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using MathematicallySafe.Armourer.Base;
using MathematicallySafe.HeadCounter.Data.Common;

namespace MathematicallySafe.HeadCounter.Data.Models
{
    public enum Period
    {
        Short,
        Long,
        Lifetime
    }

    [Serializable]
    public class Options
    {
        public string GuildName { get; set; }
        public WowRegion Region { get; set;}
        public string Realm { get; set; }
        public int ShortPeriodLength { get; set; }
        public int LongPeriodLength { get; set; }
        public Period DefaultPeriod { get; set; }
        public int iLevelBase { get; set; }
        public int iLevelProgression { get; set; }
        public int iLevelTierDifference { get; set; }
        public int MaxEffectiveAttendancePercent { get; set; }
        public int MinAttendancePercent { get; set; }
        public int MinAttendanceCount { get; set; }
        public bool ReportOptionalRaids { get; set; }
        public double HighAttendancePercentage { get; set; }
        public double GoodAttendancePercentage { get; set; }
        public double FairAttendancePercentage { get; set; }
        public List<LootOverride> Overrides { get; set;}
        public bool AutoApplyAttendanceCreditToDeletedRaiders { get; set; }

        public bool ShowShortPeriodAllAttendance { get; set; }
        public bool ShowShortPeriodAttendance { get; set; }
        public bool ShowLongPeriodAttendance { get; set; }
        public bool ShowLongPeriodAllAttendance { get; set; }
        public bool ShowLifetimeAttendance { get; set; }
        public bool ShowLifetimeAllAttendance { get; set; }
        public bool ShowShortPeriodEffectiveAttendance { get; set; }
        public bool ShowLongPeriodEffectiveAttendance { get; set; }
        public bool ShowLifetimeEffectiveAttendance { get; set; }
        public bool ShowShortPeriodLootCount { get; set; }
        public bool ShowLongPeriodLootCount { get; set; }
        public bool ShowLifetimeLootCount { get; set; }
        public bool ShowShortPeriodLootValue { get; set; }
        public bool ShowLongPeriodLootValue { get; set; }
        public bool ShowLifetimeLootValue { get; set; }
        public bool ShowShortPeriodLootRate { get; set; }
        public bool ShowLongPeriodLootRate { get; set; }
        public bool ShowLifetimeLootRate { get; set; }
        public bool ShowShortPeriodLootWeightedValue { get; set; }
        public bool ShowLongPeriodLootWeightedValue { get; set; }
        public bool ShowLifetimeLootWeightedValue { get; set; }
        public bool ShowShortPeriodWeightedLootRate { get; set; }
        public bool ShowLongPeriodWeightedLootRate { get; set; }
        public bool ShowLifetimeWeightedLootRate { get; set; }
        public bool ShowShortPeriodLootPriority { get; set; }
        public bool ShowLongPeriodLootPriority { get; set; }
        public bool ShowLifetimeLootPriority { get; set; }

    }

    [Serializable]
    public class UserOptions
    {
        public string HeadCounterPath { get; set; }
        public int MaxBackups { get; set; }
        public string FTPDomain { get; set; }
        public string FTPPath { get; set; }
        public string FTPUserName { get; set; }
        public string FTPPassword { get; set; }
    }

    public static class OptionsExtentions
    {
        public static void AddDefaultLootOverrides(this Options options)
        {
            if (options.Overrides == null)
            {
                options.Overrides = new List<LootOverride>();
            }

            // Trophy of the Crusade
            MakeLootOverride(options, 47242, 245, LootSlot.Chest);

            // Head of Onyxia
            MakeLootOverride(options, 49644, 245, LootSlot.Head);

            // Tier 10 Marks
            MakeLootOverride(options, 52025, 264, LootSlot.Chest);
            MakeLootOverride(options, 52026, 264, LootSlot.Chest);
            MakeLootOverride(options, 52027, 264, LootSlot.Chest);

            // Tier 10.5 (Hard mode)
            MakeLootOverride(options, 52028, 277, LootSlot.Chest);
            MakeLootOverride(options, 52029, 277, LootSlot.Chest);
            MakeLootOverride(options, 52030, 277, LootSlot.Chest);

            // Shadowmourne Quest items.
            MakeLootOverride(options, 50226, 277, LootSlot.TwoHand);
            MakeLootOverride(options, 50231, 277, LootSlot.TwoHand);
            
        }

        private static void MakeLootOverride(Options options, int id, int iLevel, LootSlot slot)
        {
            if (options.Overrides.FirstOrDefault(o => o.id == id) == null)
            {
                options.Overrides.Add(new LootOverride
                                      {
                                          id = id,
                                          iLevel = iLevel,
                                          Slot = slot
                                      });
            }
        }
    }
}